home *** CD-ROM | disk | FTP | other *** search
/ Amiga Format CD 43 / Amiga Format CD43 (1999)(Future Publishing)(GB)(Track 1 of 2)[!][issue 1999-09].iso / -serious- / wb / backclock / sources / timer.c < prev    next >
C/C++ Source or Header  |  1999-06-15  |  2KB  |  57 lines

  1. /*****************************************************************************
  2.  *
  3.  * Nom:                timer.c
  4.  * Desc:                handle timer
  5.  *
  6.  *
  7.  * version             : $VER: timer.c 1.11 (05.06.99)
  8.  *
  9.  *****************************************************************************
  10.  */ 
  11.  
  12. #include <proto/exec.h>
  13. #include <devices/timer.h> 
  14. #include <exec/io.h>
  15. #include "utils.h"
  16. #include "timer.h" 
  17. #include <clib/rtracker_protos.h>
  18. #include <pragmas/rtracker_pragmas.h>
  19.  
  20. extern struct Library * RTrackerLibrary ;
  21.  
  22. int initTimer(idWin * prj) {
  23.   // retourne TRUE si initialisation ok  
  24.   int ret = FALSE ;
  25.   
  26.   prj->timerok = FALSE ; // ok (pour le refermer)
  27.   if ((prj->trport = NewCreateMsgPort()) != NULL) {
  28.     // creation port message ok
  29.     if ((prj->treq = (struct timerequest *)NewCreateIORequest(prj->trport, sizeof(struct timerequest))) != NULL) {
  30.       // creation ioreq ok
  31.       if (!OpenDevice(TIMERNAME, UNIT_VBLANK, (struct IORequest*)prj->treq, 0)) {
  32.         // ouverture timer ok
  33.         ret = TRUE ;
  34.         prj->timerok = TRUE ;
  35.       }
  36.     }    
  37.   }
  38.   return ret ;
  39. }
  40. void closeTimer(idWin * prj) {
  41.   if (prj->timerok)
  42.     CloseDevice((struct IORequest*)prj->treq) ;
  43.   if (prj->treq)
  44.     NewDeleteIORequest((struct IORequest*)prj->treq) ;
  45.   if (prj->trport)
  46.     NewDeleteMsgPort(prj->trport) ;
  47. }
  48. void runtimer(idWin * prj, long seconds) {
  49.   /* lance le timer
  50.    */
  51.   if (prj->timerok) {
  52.     prj->treq->tr_time.tv_secs = seconds ;
  53.     prj->treq->tr_time.tv_micro = NULL ;
  54.     prj->treq->tr_node.io_Command = TR_ADDREQUEST ;
  55.     SendIO((struct IORequest *)prj->treq) ;
  56.   }
  57. }